Skip to content

PG-2512: Secure-erase sensitive data#39

Open
dutow wants to merge 1 commit into
Percona-Lab:masterfrom
dutow:secureerase
Open

PG-2512: Secure-erase sensitive data#39
dutow wants to merge 1 commit into
Percona-Lab:masterfrom
dutow:secureerase

Conversation

@dutow

@dutow dutow commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Since the library deals with (private) keys and other possible secure data, we should make sure that everything we do uses a secure erase allocator.

This is an API-breaking change since we have to modify the interface to use proper allocators.

Since the library deals with (private) keys and other possible secure
data, we should make sure that everything we do uses a secure erase
allocator.

This is an API-breaking change since we have to modify the interface to
use proper allocators.

@jeltz jeltz left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a full review, jsut took a quick look. One of the trickiest parts with reviewing this is making sure we have covered everything which may affect the public interfaces.

::memset_s(p, n, 0, n);
#elif defined(__GLIBC__) && \
(__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25))
// glibc >= 2.25 and the BSDs provide explicit_bzero.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment is a bit funny as is is gated behind glibc only.

}
// Compiler barrier so the writes are not reordered/coalesced away.
__asm__ __volatile__("" : : "r"(p) : "memory");
#endif

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need the fallback? glibc 2.25 was released in 2017. Does our C++ even compile on such ancient platforms?

* dead-store elimination target: the optimizer sees the memory is never read
* again and removes the write, leaving secrets in place. secure_clear routes
* through a platform "explicit" zeroing primitive when available and falls
* back to a volatile write loop otherwise, so the store always happens.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this comment is a bit unnecessary and can be shortened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants